import { Logout } from "../event/logout";
import { Login } from "../event/login";
import { AppNotificationEnum } from "./const";
import type { AppNotification } from "../event/base";

// 全局事件
const GlobalNotification: Record<AppNotificationEnum, AppNotification> = {
    logout: Logout,
    login: Login,
};

// 每个事件 是否 处理的标志
const GlobalNotificationHandleStatus: Record<AppNotificationEnum, boolean> = {
    login: false,
    logout: false,
};

// 更新
function updateGlobalEventStatus(notification: AppNotificationEnum, hasHandle: boolean) {
    GlobalNotificationHandleStatus[notification] = hasHandle;
}

// 重置
function resetGlobalEventStatus() {
    let keys = Object.keys(GlobalNotificationHandleStatus) as AppNotificationEnum[];
    keys.forEach((e) => {
        GlobalNotificationHandleStatus[e] = false;
    });
}

export {
    GlobalNotification,
    resetGlobalEventStatus,
    GlobalNotificationHandleStatus,
    updateGlobalEventStatus,
};
